package com.rayo.accesscontrollercopy.model.db.dao;

import com.litesuits.orm.db.assit.QueryBuilder;
import com.rayo.accesscontrollercopy.model.db.DbHelp;
import com.rayo.accesscontrollercopy.model.db.bean.EventData;

import java.util.List;

/**
 * Created by yanghaojie on 16/7/27.
 */
public class EventImpl implements EventDao {
    @Override
    public List<EventData> findAll() {
        return DbHelp.getQueryAll(EventData.class);
    }

    @Override
    public List<EventData> findByLimit(int limit) {
        QueryBuilder qb = new QueryBuilder(EventData.class).orderBy(EventData.EDIT_TIME).limit(0, limit);
        return DbHelp.liteOrm.query(qb);
    }

    @Override
    public void addAll(List<EventData> eventData) {
        DbHelp.insertAll(eventData);
    }

    @Override
    public void addEvent(EventData eventData) {
        DbHelp.insert(eventData);
    }

    @Override
    public void deleteAll(List<EventData> eventData) {
        for (EventData event : eventData)
            DbHelp.delete(event);
    }

    @Override
    public void deleteAll() {
        DbHelp.deleteAll(EventData.class);
    }
}

